import json
from fastapi import APIRouter,Depends
from backend.common.cache import get_redis
from backend.tasks.task1 import add


router = APIRouter()

@router.get("/test/set")
async def test_set(redis=Depends(get_redis)):
    """
    测试set
    """
    data = {"foo": "bar", "num": 123}
    await redis.set("test", json.dumps(data))
    return {"message": "set success"}

@router.get("/test/add")
async def test_add():
    """
    测试add
    """
    result = add.delay(1, 2)
    return {"message": "add success", "task_id": result.id}